Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Set functions #247

Merged
merged 1 commit into from
Oct 15, 2024
Merged

Add Set functions #247

merged 1 commit into from
Oct 15, 2024

Conversation

andriijas
Copy link
Contributor

@andriijas andriijas commented Oct 15, 2024

Adds these missing functions

Set.difference
Set.intersection
Set.union
Set.symmetricDifference
Set.isSubsetOf
Set.isSupersetOf
Set.isDisjointFrom

Also adds convinience function Set.toArray which lets you get the array of the set directly

Before (still valid):

arr->Set.fromArray->Set.values->Array.fromIterator

New, shorter:

arr->Set.fromArray->Set.toArray

Creating a set from an array and then get the array of the set is a common pattern in javascript to remove duplicates from an array

ie

  let set = Set.fromArray(["apple", "orange", "apple", "banana"])
  set->Set.toArray // ["apple", "orange", "banana"]

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set

@andriijas andriijas force-pushed the main branch 2 times, most recently from 1ac578f to fe34e4b Compare October 15, 2024 07:33
@zth zth self-requested a review October 15, 2024 11:48
@zth
Copy link
Collaborator

zth commented Oct 15, 2024

😍

@andriijas could you add a link to MDN in the docstring of each of the newer Set methods you're binding to here? Then ready to go!

 Set.difference
 Set.intersection
 Set.union
 Set.symmetricDifference
 Set.isSubsetOf
 Set.isSupersetOf
 Set.isDisjointFrom
 Set.toArray
@andriijas
Copy link
Contributor Author

@zth updated PR ✅

Note: purposely left out https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/entries and https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/keys

I dont think those make sense on Set, I guess some javascript guy at tc39 thought it would be nice convenience to have same methods as on Map

Copy link
Collaborator

@zth zth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fantastic!

@zth zth merged commit 8d81863 into rescript-lang:main Oct 15, 2024
6 checks passed
@zth
Copy link
Collaborator

zth commented Oct 16, 2024

Out in 1.6.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants